﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Public;

namespace DAL
{
    public class QuocTichDAL
    {
        public static List<QuocTichPublic> LoadQuocTich()
        {
            var quoctich = Common.db.ExecuteStoreQuery<QuocTichPublic>(@"select * from QuocTich");
            return quoctich.ToList();
        }

        public static void InsertQuocTich(QuocTichPublic _qt)
        {
            QuocTich qt = new QuocTich();
            qt.MaQT = _qt.MaQT;
            qt.TenQuocTich = _qt.TenQuocTich;
            Common.db.AddToQuocTiches(qt);
            Common.db.SaveChanges();
        }

        public static QuocTichPublic LoadMaQT()
        {
            var maqt = Common.db.ExecuteStoreQuery<QuocTichPublic>(@"select Max(MaQT) as MaQT  from QuocTich");
            return maqt.FirstOrDefault();
        }

        public static QuocTichPublic GetQuocTichByMaQT(int MaQT)
        {
            var quoctich = Common.db.ExecuteStoreQuery<QuocTichPublic>(@"select TenQuocTich from QuocTich where MaQT=" + MaQT);
            return quoctich.FirstOrDefault();
        }
    }
}
